from CvPythonExtensions import *

import GerikSpells
from GerikSpells import GerikSpellBase
from GSGroupPolicies import GSAll as GSGroup
from GSHandlerPolicies import GSTargetting as GSHandler

from GSTargetInfoPolicies import GSSinglePlotTarget
from GSGraphicsPolicies import GSPlot

from GSResultsPolicies import GSMission as GSResults

import CvUtil

gc = CyGlobalContext()

PLOT_SQUARE_SIZE = 1

class BurnLand(GerikSpellBase, GSGroup, GSHandler, GSResults):
    def __init__(self):
        GerikSpellBase.__init__(self)
        GSGroup.__init__(self)
        GSHandler.__init__(self)
        GSResults.__init__(self, GSSinglePlotTarget())

    def canUnitCast(self, pCastingUnit, pPlot, bVisible):
        if (pCastingUnit.getUnitType() == gc.getInfoTypeForString("UNIT_WARRIOR")):
            return True

    # Pre-spell-activation functions
    def createTargettingStageList(self, bAlt, bCtrl, bShift):
        stageList = []

        pPlotTargetPolicy = GSSinglePlotTarget(self.canTargetPlot)
        pPlotTargetPolicy.setCheckVisibility(False)
        pPlotGraphicsPolicy = GSPlot()
        pPlotGraphicsPolicy.setAffectedPlotColor("COLOR_RED", 1.0)
        stageList.append( (pPlotTargetPolicy, pPlotGraphicsPolicy) )
        return stageList


    # In-spell-activation Functions
    def canTargetPlot(self, pCastingGroup, pCastingPlot, pPotentialTarget, bVisible):
        return True
            

    # Post-spell-activation functions.
    def startSpellResults(self, pCastingGroup, pTargetInfo):
        CyEngine().triggerEffect(gc.getInfoTypeForString("EFFECT_EXPLOSION_01"), pTargetInfo.getTarget().getPoint())
        GSResults.startSpellResults(self, pCastingGroup, pTargetInfo)

    def startSpellResultsOnTarget(self, pCastingGroup, pTarget):
        pTarget.setPlotType(PlotTypes.PLOT_LAND, False, False)
        pTarget.setTerrainType(gc.getInfoTypeForString("TERRAIN_DESERT"), True, True)
         
